<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>
			<%= title %>
		</title>
		<%- include('../include/stylelist') %>
		<%- include('../include/scriptlist') %>
	</head>

	<body class="layui-layout-body">
		<div class="layui-layout layui-layout-admin">
			<%- include('../include/head',{title:'woyao.tv'})  %>
			<%- include('../include/left',{title:'woyao.tv'})  %>

			<div class="layui-body">
				<!-- 内容主体区域 -->
				<div style="padding: 15px;">
					<table class="layui-table" lay-data="{url:'/admin/api/index/user',method:'post', page:true, id:'idTest',limit:'10'}" lay-filter="demo">
						<thead>
							<tr>
								<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
								<th lay-data="{field:'User_id', width:130, sort: true, fixed: true}">ID</th>
								<th lay-data="{field:'User', width:100}">登录帐号</th>
								<th lay-data="{field:'Name', width:130}">用户名</th>
								<th lay-data="{field:'Sex', width:80,templet:'#sexTpl'}">性别</th>
								<th lay-data="{field:'UserIntro', width:130}">个人签名</th>
								<th lay-data="{field:'SubNumber', width:100}">投稿数量</th>
								<th lay-data="{field:'Email', width:100}">安全邮箱</th>
								<th lay-data="{field:'CentNumber', width:100}">评论数量</th>
								<th lay-data="{field:'ColleNumber', width:100}">收藏数量</th>
								<th lay-data="{field:'InforNumber', width:100}">消息数量</th>
								<th lay-data="{field:'CentStop', width:100}">禁止评论</th>
								<th lay-data="{field:'SubStop', width:100}">禁止投稿</th>
								<th lay-data="{field:'LogStop', width:100}">禁止登录</th>
								<th lay-data="{field:'WoB', width:100}">积分</th>
								<th lay-data="{field:'RegTime', width:130,templet:'#RegTimeTpl'}">注册时间</th>
								<th lay-data="{field:'RegIp', width:130}">注册ip</th>
								<th lay-data="{field:'LogTime', width:130,templet:'#LogTimeTpl'}">最后登录</th>
								<th lay-data="{field:'LogIp', width:130}">最后登录ip</th>
								<th lay-data="{fixed: 'right', width:120, align:'center', toolbar: '#barDemo'}"></th>
							</tr>
						</thead>
					</table>

					<script type="text/html" id="barDemo">
						<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
						<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
						<!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
					</script>

					<!-- 性别判断 -->
					<script type="text/html" id="sexTpl">
						{{# if(d.Sex == '3'){ }} 保密 {{# } else if(d.Sex == '2') { }} 女 {{# }else if(d.Sex == '1') { }} 男 {{# } }}
					</script>
					<!-- 注册时间格式化 -->
					<script type="text/html" id="RegTimeTpl">
						{{d.RegTime = d.RegTime.replace(/T/,' ').replace('.000Z','')}}
					</script>
					<!-- 登录时间格式化 -->
					<script type="text/html" id="LogTimeTpl">
						{{d.LogTime = d.LogTime.replace(/T/,' ').replace('.000Z','')}}
					</script>
				</div>
			</div>
			<!-- 编辑弹出层 -->
			<div class="layui-form layui-form-pane" id="modal" style="display: none;padding:20px;">
				<div class="layui-form-item">
					<label class="layui-form-label">ID</label>
					<div class="layui-input-block">
						<input type="text" name="User_id" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">登录帐号</label>
					<div class="layui-input-block">
						<input type="text" name="User" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="Sex" value="1" title="男" lay-skin="radio" lay-filter="filter">
						<input type="radio" name="Sex" value="2" title="女" lay-skin="radio" lay-filter="filter">
						<input type="radio" name="Sex" value="3" title="保密" lay-skin="radio" lay-filter="filter">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">个人签名</label>
					<div class="layui-input-block">
						<input type="text" name="UserIntro" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">安全邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="Email" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止评论</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="CentStop" lay-skin="switch" lay-filter="CentStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止投稿</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="SubStop" lay-skin="switch" lay-filter="SubStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止登录</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="LogStop" lay-skin="switch" lay-filter="LogStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">积分</label>
					<div class="layui-input-block">
						<input type="text" name="WoB" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
					</div>
				</div>
			</div>

			<!-- 查看弹出层 -->
			<div class="layui-form layui-form-pane" id="ViewsModal" style="display: none;padding:20px;">
				<div class="layui-form-item">
					<label class="layui-form-label">ID</label>
					<div class="layui-input-block">
						<input type="text" name="Views_User_id" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">登录帐号</label>
					<div class="layui-input-block">
						<input type="text" name="Views_User" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="Views_Sex" value="1" disabled title="男" lay-skin="radio" lay-filter="filter">
						<input type="radio" name="Views_Sex" value="2" disabled title="女" lay-skin="radio" lay-filter="filter">
						<input type="radio" name="Views_Sex" value="3" disabled title="保密" lay-skin="radio" lay-filter="filter">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">个人签名</label>
					<div class="layui-input-block">
						<input type="text" name="Views_UserIntro" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">安全邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="Views_Email" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止评论</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="Views_CentStop" disabled lay-skin="switch" lay-filter="CentStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止投稿</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="Views_SubStop" disabled lay-skin="switch" lay-filter="SubStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item" pane="">
					<label class="layui-form-label">禁止登录</label>
					<div class="layui-input-block">
						<input type="checkbox" checked="" name="Views_LogStop" disabled lay-skin="switch" lay-filter="LogStop" title="开关">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">积分</label>
					<div class="layui-input-block">
						<input type="text" name="Views_WoB" value="" disabled lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-footer">
				<!-- 底部固定区域 -->
				© WoYao.Tv - 底部固定区域
			</div>
		</div>
		<script>
			//JavaScript代码区域
			layui.use('element', function() {
				var element = layui.element;
			});
			var form, laydata, laydataobj;
			layui.use('form', function() {
				form = layui.form;
				form.on('switch(CentStop)', function(data) {
					layer.msg((this.checked ? '禁止用户评价' : '允许用户评价'), {
						offset: 'auto'
					});
				});
				form.on('switch(SubStop)', function(data) {
					layer.msg((this.checked ? '禁止用户投稿' : '允许用户投稿'), {
						offset: 'auto'
					});
				});
				form.on('switch(LogStop)', function(data) {
					layer.msg((this.checked ? '禁止用户登录' : '允许用户登录'), {
						offset: 'auto'
					});
				});
				form.on('submit(demo1)', function(obj) {
					obj.field.CentStop = (obj.field.CentStop ? 1 : 0)
					obj.field.SubStop = (obj.field.SubStop ? 1 : 0)
					obj.field.LogStop = (obj.field.LogStop ? 1 : 0)
					$.ajax({
						url: '/admin/api/index/useredit',
						type: 'post',
						datatype: 'json',
						data: obj.field,
						success: function(data) {
							if(data.code > 0) {
								layer.msg(data.msg)
								return false;
							}
							layer.msg(data.msg);
							laydataobj.update(obj.field);

						},
						error: function(err) {
							console.log(err)
						}
					})
					return false;
				});
			});
			layui.use('table', function() {
				var table = layui.table;
				//监听工具条
				table.on('tool(demo)', function(obj) {
					laydataobj = obj;
					laydata = obj.data;
					if(obj.event === 'detail') {
						var ViewsModal = $("#ViewsModal");
						ViewsModal.find("[name=Views_User_id]").val(laydata.User_id);
						ViewsModal.find("[name=Views_User]").val(laydata.User);
						for(var i = 0; i < ViewsModal.find("[name=Views_Sex]").length; i++) {
							if(laydata.Sex == ViewsModal.find("[name=Views_Sex]").eq(i).val()) {
								ViewsModal.find("[name=Views_Sex]").eq(i).prop("checked", "true");
							}
						}
						ViewsModal.find("[name=Views_UserIntro]").val(laydata.UserIntro);
						ViewsModal.find("[name=Views_Email]").val(laydata.Email);
						(laydata.CentStop == 0) ? ViewsModal.find("[name=Views_CentStop]").prop("checked", false): ViewsModal.find("[name=Views_CentStop]").prop("checked", true);
						(laydata.SubStop == 0) ? ViewsModal.find("[name=Views_SubStop]").prop("checked", false): ViewsModal.find("[name=Views_SubStop]").prop("checked", true);
						(laydata.LogStop == 0) ? ViewsModal.find("[name=Views_LogStop]").prop("checked", false): ViewsModal.find("[name=Views_LogStop]").prop("checked", true);
						ViewsModal.find("[name=Views_WoB]").val(laydata.WoB);
						form.render('');
						Wo.offset("auto", ViewsModal);
					} else if(obj.event === 'edit') {
						var Modal = $("#modal");
						Modal.find("[name=User_id]").val(laydata.User_id);
						Modal.find("[name=User]").val(laydata.User);
						for(var i = 0; i < Modal.find("[name=Sex]").length; i++) {
							if(laydata.Sex == Modal.find("[name=Sex]").eq(i).val()) {
								Modal.find("[name=Sex]").eq(i).prop("checked", "true");
							}
						}
						Modal.find("[name=UserIntro]").val(laydata.UserIntro);
						Modal.find("[name=Email]").val(laydata.Email);
						(laydata.CentStop == 0) ? Modal.find("[name=CentStop]").prop("checked", false): Modal.find("[name=CentStop]").prop("checked", true);
						(laydata.SubStop == 0) ? Modal.find("[name=SubStop]").prop("checked", false): Modal.find("[name=SubStop]").prop("checked", true);
						(laydata.LogStop == 0) ? Modal.find("[name=LogStop]").prop("checked", false): Modal.find("[name=LogStop]").prop("checked", true);
						Modal.find("[name=WoB]").val(laydata.WoB);
						form.render('');
						Wo.offset("auto", Modal);
					}
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('idTest');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.demoTable .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
		</script>
	</body>

</html>